#!/bin/sh
#
# /etc/rc.d/samba: start/stop samba daemons
#

SSD=/sbin/start-stop-daemon
SMB=/usr/sbin/smbd
NMB=/usr/sbin/nmbd
SMB_PID=/var/run/samba/smbd.pid
NMB_PID=/var/run/samba/nmbd.pid


print_status() {
	$SSD --status --pidfile $2
	case $? in
	0) echo "$1 is running with pid $(cat $2)" ;;
	1) echo "$1 is not running but the pid file $2 exists" ;;
	3) echo "$1 is not running" ;;
	4) echo "Unable to determine the program status" ;;
	esac
}

case $1 in
start)
	$SSD --start --pidfile $NMB_PID --exec $NMB -- -D
	$SSD --start --pidfile $SMB_PID --exec $SMB -- -D
	;;
stop)
	$SSD --stop --retry 10 --pidfile $SMB_PID 
	$SSD --stop --retry 10 --pidfile $NMB_PID 
	;;
restart)
	$0 stop
	$0 start
	;;
reload)
	/usr/bin/smbcontrol smbd reload-config
	/usr/bin/smbcontrol nmbd reload-config
	;;
status)
	print_status $SMB $SMB_PID
	print_status $NMB $NMB_PID
	;;
baslat)
	$SSD --start --pidfile $NMB_PID --exec $NMB -- -D
	$SSD --start --pidfile $SMB_PID --exec $SMB -- -D
	;;
durdur)
	$SSD --stop --retry 10 --pidfile $SMB_PID 
	$SSD --stop --retry 10 --pidfile $NMB_PID 
	;;
ybaslat)
	$0 stop
	$0 start
	;;
yyukle)
	/usr/bin/smbcontrol smbd reload-config
	/usr/bin/smbcontrol nmbd reload-config
	;;
durum)
	print_status $SMB $SMB_PID
	print_status $NMB $NMB_PID
	;;
*)
	echo "Kullanımı: $0 [baslat|durdur|ybaslat|yyukle|durum]"
	echo "Usage: $0 [start|stop|restart|reload|status]"
	;;
esac

# End of file
